const parameter = getApp().globalData.parameter
const domainName = getApp().globalData.domainName

// 加载权限列表
const page_init=(that)=>{
  wx.request({
    url: domainName + '/pilot_init',
    data: {},...parameter,
    success: res => {
      that.setData({
        list:res.data.rank_list,
      })
    },
  })
}


// 设置选项
const set_opt=(that,e)=>{
  let index = e.currentTarget.id
  var row_id = that.data.list[index].id
  var name = that.data.list[index].name
  wx.showActionSheet({
    itemList: ['配置【等级-理论章】','修改名称'],
    success: res => {
      // console.log('tapIndex',res.tapIndex)
      if(res.tapIndex==0){  // 类别
        wx.navigateTo({
          url:'/pages/sysConfig/config_license/config_rank_chap/config_rank_chap?id=' + row_id + '&name=' + name,
        })
      }else if(res.tapIndex==1){
        wx.showModal({
          content:name,
          editable: true,
          placeholderText: '请输入新名词',
          showCancel: true,
          title: '修改名称',
          success: res => {
            if(res.confirm){
              wx.request({
                url: domainName + '/update_pilotRankName',
                data: {
                  row_id:row_id,
                  new_name:res.content,
                },...parameter,
                success: res => {
                  wx.showToast({
                    title: '修改完成',
                    duration: 1500,
                    icon: 'success',
                  })
                  that.setData({
                    list:res.data.rank_list
                  })
                },
              })
            }
          },
        })
      }
    },
  })

}


// pages/mana_right/mana_right.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show_list:[],
  },


tap_chap(e){
  console.log('e',e)
  let index1 = e.currentTarget.dataset.index1
  let index2 = e.currentTarget.dataset.index2
  let Pilot_rank_chap_id = this.data.list[index1].chap_list[index2].Pilot_rank_chap_id
  wx.showActionSheet({
    itemList: ['删除'],
    success: res => {
      if(res.tapIndex==0){
        wx.showModal({
          content: '确定要删除吗？',
          showCancel: true,
          title: '警告',
          success: res => {
            if(res.confirm){
              wx.request({
                url: domainName + '/pilot_delete_chap',
                data: {Pilot_rank_chap_id},...parameter,
                success: res => {
                  if(res.data.delete_res){
                    wx.showToast({
                      title: '删除完成！',
                    })

                    this.data.list[index1].chap_list.splice(index2,1)
                    this.setData({
                      list:this.data.list
                    })
                  }
                },
              })
            }
          },
        })
      }
    },
  })


},


  set_opt(e){set_opt(this, e)},

  tap_row1(e){
    let rank_id = this.data.list[e.currentTarget.id].id
    let show_list = this.data.show_list
    let of_index = show_list.indexOf(rank_id)
    if(of_index>-1){
      show_list.splice(of_index,1)
    }else{
      show_list.push(rank_id)
    }
    this.setData({
      show_list:show_list
    })
  },



  onLoad:function(options){
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    page_init(this)
  },

  

})